;export default function () {
    var ls = localStorage.getItem("usr_info");
    if (ls !== null) {
        var ls_list = JSON.parse(ls);
        var status = false;
        var usr = "";
        $.each(ls_list, function (index, item) {
            if (item.status == "success") {
                status = true;
                usr = item.usr;
                return false;
            }
        });
        if(status){
            alert(`用户 ${usr} 已登录`);
            location.href="http://localhost:8888/html/";
        }
    }
    $(".loginbtn_block").on("click", "a", function () {
        $(this).addClass("curClick").siblings().removeClass("curClick");
        if ($(this).html() === "普通登录") {
            $(".login_form").attr("style", "display:block;");
            $(".register_form").attr("style", "display:none;");
        }
        else {
            $(".login_form").attr("style", "display:none;");
            $(".register_form").attr("style", "display:block;");
        }
    });
    $("label").on("click", function () {
        // console.log(this);
        // $(this).attr("style","display:none;");
        $(this).prev()["0"].focus();
    });
    $(".on-or-off").on("focus", function () {
        $($(this).next()).attr("style", "display:none;");
    });
    $(".on-or-off").on("blur", function () {
        if ($(this).val() === "") {
            $($(this).next()).attr("style", "display:block;");
            if ($(this).attr("name") === "username") {
                $(this).parent().children()[3].innerHTML = "请输入登录名";
            }
            if ($(this).attr("name") === "password") {
                $(this).parent().children()[4].innerHTML = "密码不能少于6位";
            }
        }
        else {
            if ($(this).attr("name") === "username") {
                $(this).parent().children()[3].innerHTML = "&nbsp;";
            }
            if ($(this).attr("name") === "password" && $(this).val().length < 6) {
                $(this).parent().children()[4].innerHTML = "密码不能少于6位";
            }
            if ($(this).attr("name") === "password" && $(this).val().length >= 6) {
                $(this).parent().children()[4].innerHTML = "&nbsp;";
            }
        }
    });
    $(".js_submit").on("click", function () {
        if ($(this).hasClass("login-btn")) {
            // console.log("login!");
            var usr = $("#shop_login_username").val();
            var pwd = $("#shop_login_password").val();
            // console.log(usr,pwd);
            if (usr === "" || pwd === "") {
                alert("不能为空!");
                return false;
            }
            if (pwd.length < 6) {
                alert("密码不能少于6位");
                return false;
            }
            else {
                var ls = localStorage.getItem("usr_info");
                if (ls === null) {
                    alert("未注册");
                    $("input").val("");
                    $("label").attr("style", "display:block;");
                    return false;
                }
                else {
                    var ls_list = JSON.parse(ls);
                    var success = false;
                    $.each(ls_list, function (index, item) {
                        if (usr == item.usr && pwd == item.pwd) {
                            success = true;
                            ls_list[index].status = "success";
                            console.log(ls_list);
                            localStorage.setItem("usr_info", JSON.stringify(ls_list));
                            return false;
                        }
                    });
                    if (success) {
                        alert("登录成功");
                        $("input").val("");
                        $("label").attr("style", "display:block;");
                        location.href = "http://localhost:8888/html/";
                    }
                    else {
                        alert("未注册");
                        $("input").val("");
                        $("label").attr("style", "display:block;");
                        return false;
                    }
                }
            }
        }
        else {
            // console.log("register!");
            var usr = $("#shop_register_username").val();
            var pwd1 = $("#shop_register_password1").val();
            var pwd2 = $("#shop_register_password2").val();
            // console.log(usr,pwd1,pwd2);
            if (usr === "" || pwd1 === "" || pwd2 === "") {
                alert("不能为空!");
                return false;
            }
            if (pwd1.length < 6 || pwd2.length < 6) {
                alert("密码不能少于6位");
                return false;
            }
            if (pwd1 !== pwd2) {
                alert("两次输入的密码不同");
                return false;
            }
            else {
                var ls = localStorage.getItem("usr_info");
                // console.log(ls);
                if (ls === null) {
                    var info = [{ usr, pwd: pwd1 }];
                    localStorage.setItem("usr_info", JSON.stringify(info));
                    $("input").val("");
                    $("label").attr("style", "display:block;");
                    alert("注册成功");
                    return false;
                }
                else {
                    var ls_list = JSON.parse(ls);
                    var has_same_usr = false;
                    $.each(ls_list, function (index, item) {
                        if (usr == item.usr) {
                            $("input").val("");
                            $("label").attr("style", "display:block;");
                            alert("用户名已被注册");
                            has_same_usr = true;
                            return false;
                        }
                    });
                    if (has_same_usr) return false;
                    ls_list.push({ usr, pwd: pwd1 });
                    localStorage.setItem("usr_info", JSON.stringify(ls_list));
                    $("input").val("");
                    $("label").attr("style", "display:block;");
                    alert("注册成功");
                }
            }
        }
    });
}